using System;
using MathNet.Numerics.LinearAlgebra.Double;


namespace MRIData
{
	public class Volume<T> where T:IComparable
	{
		T[,,] m_volumeData;
		Matrix m_transform;
		
		public Volume()
		{
			m_volumeData = new T[0,0,0];
			
			m_transform = DenseMatrix.Identity(4);
			
		}
		
		public Volume(T[,,] volumeData)
		{
			m_volumeData = volumeData;
			
			m_transform = DenseMatrix.Identity(4);
			m_transform[0,3] = m_volumeData.GetLength(0) / 2.0d;
			m_transform[1,3] = m_volumeData.GetLength(1) / 2.0d;
			m_transform[2,3] = m_volumeData.GetLength(2) / 2.0d;
		}
		
		public Volume(T[,,] volumeData, Matrix transform)
		{
			m_volumeData = volumeData;
			m_transform = transform;
		}
		
		public Volume<bool> BinaryVolume(T reference)
		{
			bool[,,] volumeData = new bool[m_volumeData.GetLength(0), m_volumeData.GetLength(1), m_volumeData.GetLength(2)];
			
			for(int x = 0; x<m_volumeData.GetLength(0); x++)
			{
				for(int y = 0; y<m_volumeData.GetLength(1); y++)
				{
					for(int z=0; z<m_volumeData.GetLength(2); z++)
					{
						if(m_volumeData[x,y,z].CompareTo(reference) < 0)
						{
							volumeData[x,y,z] = false;
						}
						else
						{
							volumeData[x,y,z] = true;
						}
					}
				}
			}
			
			Volume<bool> binaryVolume = new Volume<bool>(volumeData, this.Transform);
			
			return binaryVolume;
		}
		
		public T[,,] VolumeData
		{
			get{
				return m_volumeData;
			}
			private set
			{
				m_volumeData = value;
			}
		}
		
		public Matrix Transform
		{
			get{
				return m_transform;
			}
			private set
			{
				m_transform = value;
			}
		}
	}
}

